// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-12 09:22
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.TREE;

import org.junit.jupiter.api.Test;

/**
 * 等差数列划分
 */
public class NumberOfArithmeticSlices {
    // 双指针
    public int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length, cnt = 0, pre = 0;
        for (int p = 0; p < n - 2; p++) {
            for (int q = p + 1; q < n - 1; q++) {
                for (int t = q + 1; t < n; t++) {
                    if ((t - q) == (q - p)) {
                        cnt += 1;
                        pre = t;
                    }
                    if ((t - pre) == (q - p)) {
                        cnt += 2;
                        pre = t;
                    }
                }
            }
        }
        return cnt;
    }


    @Test
    public void shout() {
        int[] nums = {1, 2, 3, 4};
        System.out.println(numberOfArithmeticSlices(nums));
    }
}
